from rest_framework import serializers

from CarQueryApp.models import Record, Car


class SearchSerializer(serializers.ModelSerializer):
    car = serializers.SerializerMethodField()
    makedate = serializers.SerializerMethodField()

    @staticmethod
    def get_makedate(record):
        return record.makedate.strftime('%Y{y}-%m{m}-%d{d}').format(y='年',m='月',d='日')

    @staticmethod
    def get_car(record):
        return CarSerializer(record.car).data

    class Meta:
        model = Record
        fields = '__all__'




class CarSerializer(serializers.ModelSerializer):

    class Meta:
        model = Car
        fields = '__all__'
